﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;
using System.Data.Services.Client;
using Microsoft.WindowsAzure;

namespace Azure.TableQuery.Tests
{
    public class TestEntityContext : TableServiceContext
    {
        public TestEntityContext(string baseAddress, StorageCredentials credentials)
            : base(baseAddress, credentials)
        { }

        public void CreateTestEntities(int count)
        {
            for (int i = 0; i < count; i++)
            {
                this.AddObject("TestEntity", GenerateEntity(i));
            }
            this.SaveChanges(SaveChangesOptions.Batch);
        }

        private TestEntity GenerateEntity(int age)
        {
            var entity = new TestEntity();

            entity.Name = Guid.NewGuid().ToString();
            entity.PartitionKey = "partition";
            entity.RowKey = Guid.NewGuid().ToString();
            entity.Age = age;
            entity.DateCreated = DateTime.Now;
            
            return entity;
        }
    }
}
